﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BusinessLayer;
using ModelLayer.Common;
using ShopKart.Common;

namespace ShopKart.Controllers
{
    public class BaseController : Controller
    {
        public SessionObject SessionObject { get; set; }
        public BaseController()
        {


        }

        //public override On
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            //if (Session["SessionObject"] == null)
            //{
            //    AccountController accountController = new AccountController();
            //    accountController.SignOut();
            //}

            DashboardManager dashboardManager = new DashboardManager();
            if (ViewData["Categories"] == null)
            {
                ViewData["Categories"] = dashboardManager.GetAllMenuCategories();
            }

            if (ViewData["UserCart"] == null)
            {
                if (((SessionObject)Session["SessionObject"]) != null)
                    ViewData["UserCart"] = ((SessionObject)Session["SessionObject"]).UserCarts;
            }

            SessionObject = ((SessionObject)Session["SessionObject"]);
        }

        public void ShowMessage(string msg, MessageTypeEnum messageTypeEnum)
        {
            ViewBag.MessageType = messageTypeEnum;
            ModelState.AddModelError(string.Empty, msg);
        }
    }
}